package com.ccb;

import java.io.IOException;

/**
 * 
 * @author flytoice
 *
 */
public abstract class CommonJob {
	
	/**
	 * 参数验证
	 * @param args
	 * @return
	 */
	private boolean check(String[] args){
		if (!paramNumCheck(args,Integer.valueOf(args[0]))) return false;
		
		return customCheck(args);
	}
	
	/**
	 * 参数数量验证
	 * @param args
	 * @param paramNum
	 * @return
	 */
	private boolean paramNumCheck(String[] args,int paramNum){
		//参数验证
		if(args.length<paramNum){
			//TODO 日志输出
			return false;
		}
		return true;
	}
	
	/**
	 * 自定义验证
	 * @return
	 */
	protected boolean customCheck(String[] args){
		return true;
	}
	
	/**
	 * 执行作业
	 * @param args
	 */
	public void run(String[] args){
		//参数验证
		if (!check(args)) return;
		
		//执行
		try {
			doTask(args);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}
	
	/**
	 * 自定义实现作业
	 * @param args
	 * @throws IOException
	 * @throws ClassNotFoundException
	 * @throws InterruptedException
	 */
	protected abstract void doTask(String[] args) throws IOException,ClassNotFoundException,InterruptedException;
	
	
}
